class ApplicationController < ActionController::Base
  protect_from_forgery
  helper_method :current_user
  before_filter :logado?, :except => :pagina_inicial

  def pagina_inicial
    render 'layouts/index.html'
  end

  def logar
    if logado?
      redirect_to :controller => "funcionarios", :action => "index"
    else
      flash[:notice] = "Usuario ou senha incorretos"
      redirect_to root_path
    end
  end

  def logado?
    unless session[:funcionario_id]
      redirect_to root_path
    end
#    usuario = Funcionario.find_by_login(params[:cpf],params[:senha])
#    if usuario.nil?
#      return false
#    else
#      return true
#    end
  end

  def current_user
    @current_user ||= Funcionario.find(session[:funcionario_id]) if session[:funcionario_id]
  end

  
end
